-
Notifications
You must be signed in to change notification settings - Fork 699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
P-chain - Memo field zeroed post Durango #2607
Conversation
@@ -65,3 +65,20 @@ func (t *BaseTx) Verify(ctx *snow.Context) error { | |||
return nil | |||
} | |||
} | |||
|
|||
func VerifyMemoFieldLength(memo types.JSONByteSlice, isDurangoActive bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a different method rather than extending SyntacticVerify
with config and chainTIme. We can revisit this choice down the line, in case other syntactic checks will depend on the specific fork used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some tests that fail verification because of non-empty memo fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see obvious errors, but I'm also not sure how to distill this much copy-pasta test code to be able to catch mistakes. I would highly recommend using table-driven testing, a set of reusable test data, and shared helkpers for this kind of testing to simplify both review and maintenance.
@@ -1003,7 +1041,951 @@ func TestStandardTxExecutorDurangoAddValidator(t *testing.T) { | |||
require.Equal(endTime, val.EndTime) | |||
} | |||
|
|||
func TestDurangoStandardTxExecutorAddPermissionlessValidatorTx(t *testing.T) { | |||
require := require.New(t) | |||
env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(No action required) Maybe use structs where naming of variables is desired (also good for optional parameters):
env := newEnvironment(t, envConfig{
postBanff: true,
postCortina: true,
postDurango: true,
},
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept this aligned with other tests. However booleans are not great. In #2169 I have cleaned it up and replace the booleans with a fork enum. I'd defer to cleanup to that PR
env.ctx.Lock.Lock() | ||
defer func() { | ||
require.NoError(shutdownEnvironment(env)) | ||
env.ctx.Lock.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok that a failure to shutdown the environment without error won't release the lock? If not, maybe shutdownEnvironment would be a better place to ensure lock release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it does not really matter in this case, since this happens at the very end of the test. But this is something that can be fixed for all tests. #2491 by @dhrubabasu fixes this concern I believe.
uint64(endTime.Unix()), | ||
nodeID, | ||
// Build the AddValidatorTx | ||
ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(No action required) Maybe extract into a helper?
}}, | ||
Subnet: testSubnet1.TxID, | ||
AssetID: ids.GenerateTestID(), | ||
InitialSupply: 10, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(No action required) Lots of magic numbers here. Even in tests, using descriptive variable names can be helpful to declare your intent (or where that is too much at least defining a struct configured with a bunch of magic numbers with an appropriately descriptive name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These numbers don't really matter here, they're just enough to pass validation.
The whole point is to showcase validation around Memo field. But to get a fully formed tx I have specified other attributes.
Perhabs I shoud mark these values as dummy...? Or even better we should probably have a single UT per transactions, carriying out all the relevant validations per fork
vms/components/avax/base_tx.go
Outdated
|
||
func VerifyMemoFieldLength(memo types.JSONByteSlice, isDurangoActive bool) error { | ||
if !isDurangoActive { | ||
return nil // already validated in SyntacticVerify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil // already validated in SyntacticVerify | |
// SyntacticVerify validates this field post-Durango | |
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -728,6 +761,10 @@ func verifyTransferSubnetOwnershipTx( | |||
return err | |||
} | |||
|
|||
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil { | |
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*=isDurangoActive*/); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -512,6 +550,10 @@ func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error { | |||
return err | |||
} | |||
|
|||
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil { | |
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*=isDurangoActive*/); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -54,13 +54,20 @@ func (e *StandardTxExecutor) CreateChainTx(tx *txs.CreateChainTx) error { | |||
return err | |||
} | |||
|
|||
var ( | |||
timestamp = e.State.GetTimestamp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: timestamp
-> currentTimestamp
to match the usage in other funcs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -98,8 +105,15 @@ func (e *StandardTxExecutor) CreateSubnetTx(tx *txs.CreateSubnetTx) error { | |||
return err | |||
} | |||
|
|||
var ( | |||
timestamp = e.State.GetTimestamp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: timestamp
-> currentTimestamp
to match the usage in other funcs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Co-authored-by: Dhruba Basu <[email protected]> Signed-off-by: Stephen Buttolph <[email protected]>
Why this should be merged
Post Durango we're going to enforce the Memo field is zero for any P-chain tx
How this works
Introduced extra checks. No changes to wallets and APIs yet. We'll revisit it post Durango activation
How this was tested
CI